<html lang="zh-cn">

	<head>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title></title>
		<style type="text/css">
			* {
				height: 100%; //设置高度，不然会显示不出来 
			}
		</style>

		<body>
			<div id="map"></div>
		</body>
		<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=NF7KOFeygG0044MEx3jnRw0eW3GPtoL1"></script>
		<!--<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>-->
		<script>
			//			$(function() {
			//				navigator.geolocation.getCurrentPosition(translatePoint); //定位 
			//			});
			//
			//			function translatePoint(position) {
			//				var currentLat = position.coords.latitude;
			//				var currentLon = position.coords.longitude;
			//				var gpsPoint = new BMap.Point(currentLon, currentLat);
			//				BMap.Convertor.translate(gpsPoint, 0, initMap); //转换坐标：gpsPoint：转换前坐标，第二个参数为转换方法，0表示gps坐标转换成百度坐标，callback回调函数，参数为新坐标点 
			//			}
			//
			//			function initMap(point) {
			//				//初始化地图 
			//				map = new BMap.Map("map");
			//				map.addControl(new BMap.NavigationControl());
			//				map.addControl(new BMap.ScaleControl());
			//				map.addControl(new BMap.OverviewMapControl());
			//				map.centerAndZoom(point, 15);
			//				map.addOverlay(new BMap.Marker(point))
			//			}

			//     运用IP获取城市名字和城市中心经纬度
			//			var myCity = new BMap.LocalCity();
			//			myCity.get(myFun);
			//			function myFun(result) {
			//				console.log(result)
			//				console.log(result.center)
			//				console.log(result.name)
			//			}

			//   运用gps获取城市经纬度
			// 百度地图API功能
			var map = new BMap.Map("map");
			var point = new BMap.Point(116.331398, 39.897445);
			map.centerAndZoom(point, 12);
			var geolocation = new BMap.Geolocation();
			var geoc = new BMap.Geocoder();
			geolocation.getCurrentPosition(function(r) {
				if(this.getStatus() == BMAP_STATUS_SUCCESS) {

					alert('您的位置：' + r.point.lng + ',' + r.point.lat);
					var convertor = new BMap.Convertor();
					var pointArr = [];
					pointArr.push(r.point);
					convertor.translate(pointArr, 1, 5, function(data) {
						if(data.status == 0) {
							geoc.getLocation(data.points[0], function(rs) {
								var addComp = rs.addressComponents;
								alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
							});
							var mk = new BMap.Marker(data.points[0]);
							map.addOverlay(mk);
							map.panTo(r.point);
						}

					})

				} else {
					alert('failed' + this.getStatus());
					//     运用IP获取城市名字和城市中心经纬度
					//			var myCity = new BMap.LocalCity();
					//			myCity.get(myFun);
					//			function myFun(result) {
					//				console.log(result)
					//				console.log(result.center)
					//				console.log(result.name)
					//			}
				}
			}, {
				enableHighAccuracy: true
			})
		</script>
	</head>

</html>